<template>
  <div class="floor-header">
    <div class="title">
      <h1>{{ title }}</h1>
      <h5>{{ tip }}</h5>
      <!-- tab切换 -->
      <div class="tab" v-if="tabs && tabs.length > 0">
        <div
          class="tab-item"
          :class="{ active: tabIndex === index }"
          v-for="(tab, index) in tabs"
          :key="index"
          @click="switchTabPanelHandler(index)">{{ tab }}</div>
      </div>
    </div>
    <div class="right">
      <!-- 分类 -->
      <div class="cate">
        <div class="cate-item" v-for="(item, index) in cates" :key="item.id" v-if="index < 7">{{ item.name }}</div>
      </div>
      <div class="more">{{ link }} &gt;</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    tip: {
      type: String,
      default: ''
    },
    link: {
      type: String,
      default: ''
    },
    tabs: {
      type: Array,
      default: () => []
    },
    cates: {
      type: Array,
      default: () => []
    }
  },

  data () {
    return {
      tabIndex: 0
    }
  },

  methods: {
    /**
     * 点击切换分页组件
     * @param { Number } index 当前索引
     */
    switchTabPanelHandler (index) {
      // 如果当前点击了tab页，则切换tab页
      this.tabIndex = index
      // 发送事件，让父组件知晓
      this.$emit('tab-change', index)
    }
  }
}
</script>

<style lang="less" scoped>
@import "./../../styles/variable";

.floor-header {
  color: @font-color;
  display: flex;
  justify-content: space-between;
  padding-bottom: 20px;
  .title {
    flex: 1;
    h1 {
      cursor: pointer;
      display: inline;
      font-size: 28px;
      font-weight: 700;
      margin-right: 20px;
      &:hover {
        color: @font-color-golden;
      }
    }
    h5 {
      display: inline;
      font-size: 14px;
    }
    .tab {
      cursor: pointer;
      display: inline-block;
      font-size: 14px;
      margin-left: 16px;
      .tab-item {
        display: inline-block;
        margin-right: 50px;
        padding: 4px;
        &:hover {
          color: @font-color-golden;
        }
        &.active {
          border-bottom: 2px solid @font-color-golden;
          color: @font-color-golden;
        }
      }
    }
  }
  .right {
    .cate {
      display: inline;
      padding-right: 20px;
      .cate-item {
        color: @font-color;
        cursor: pointer;
        display: inline;
        font-size: 14px;
        padding: 0px 12px;
        position: relative;
        &:hover {
          color: @font-color-golden;
        }
        &:after {
          content: "/";
          color: @font-color;
          position: absolute;
          right: -2px;
        }
        &:last-child {
          &:after {
            display: none;
          }
        }
      }
    }
    .more {
      cursor: pointer;
      display: inline;
      font-size: 14px;
      &:hover {
        color: @font-color-golden;
      }
    }
  }
}
</style>
